<?php
/**
 * ShopEx licence
 *
 * @copyright  Copyright (c) 2005-2010 ShopEx Technologies Inc. (http://www.shopex.cn)
 * @license  http://ecos.shopex.cn/ ShopEx License
 */
class b2c_ctl_site_feedback extends b2c_frontpage{
    function __construct(&$app){
        parent::__construct($app);
        $this->_response->set_header('Cache-Control', 'no-store');
		$this->set_tmpl('passport');
    }
   
    //注册页面
    public function index($url=null){
		$phones=app::get('b2c')->getConf('setting-phone.phone');
		$this->pagedata['phones'] = $phones;
        $this->page("site/feedback/index.html");
    }

	//提交反馈信息
	public function create(){
		//_POST过滤
        $post = utils::_filter_input($_POST);
		unset($_POST);
		$back_url = null;
		$phone_setting = $post['phone_setting'];
		$phones=app::get('b2c')->getConf('setting-phone.phone');
		foreach($phones as $v){
			$bool  = in_array($phone_setting,$v);
			if($bool){
				$len = $v['length'];
				break;
			}
		}

		if((!empty($post['tel']) && !preg_match('/^[1-9]\d{'.($len-1).'}$/', $post['tel']))){
			$this->splash('failed', $back_url, app::get('b2c')->_('手机格式错误'),true);
		}

		$Data = array(
            'tel' => $post['tel'],
            'name' => $post['name'],
			'phone_setting' => $post['phone_setting'],
			'content' => $post['content'],
			'regtime' => time()
        );
		$bool= $this->app->model('feedback')->insert($Data);
		if($bool){
			$this->splash('success', './', app::get('b2c')->_('提交成功'),true);
		}else{
			$this->splash('failed', $back_url, app::get('b2c')->_('提交失败'),true);
		}
	}
}
